package com.thermal.thermal_inspection.service.impl;

import com.thermal.thermal_inspection.entity.Classes;
import com.thermal.thermal_inspection.entity.Unit;
import com.thermal.thermal_inspection.mapper.MapDetailMapper;
import com.thermal.thermal_inspection.mapper.UnitMapper;
import com.thermal.thermal_inspection.service.UnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UnitServiceImpl implements UnitService {
    @Autowired
    UnitMapper unitMapper;
    @Autowired
    MapDetailMapper mapDetailMapper;

    /**
     *新增机组
     */
    @Override
    public int addUnit(String unitName) {
        return unitMapper.addUnit(unitName);
    }

    /**
     *删除机组
     */
    @Override
    public int deleteUnit(int unitId) {
        int rows1 = unitMapper.deleteUnit(unitId);
        int rows2 = mapDetailMapper.deleteUnit(unitId);
        return rows1;
    }

    /**
     *查找全部机组
     */
    @Override
    public List<Unit> getUnits() {
        return unitMapper.getUnits();
    }

    /**
     *机组是否存在
     */
    @Override
    public boolean existUnit(int unitId) {
        return unitMapper.selectUnit(unitId) != null;
    }

    /**
     *修改机组名字
     */
    @Override
    public int updateUnit(int unitId, String unitName) {
        return unitMapper.updateUnit(unitId, unitName);
    }

    /**
     * 查询指定机组（搜索接口）
     */
    @Override
    public List<Unit> getSpecifiedUnit(Integer unitId, String unitName){
        return unitMapper.getSpecifiedUnit(unitId, unitName);
    }

    /**
     * 判断机组名是否存在
     */
    @Override
    public boolean existUnitName(String unitName){
        return unitMapper.getUnitByName(unitName) != null;
    }
}
